package com.visikard.asynctask;

import android.os.Handler;
import android.os.Message;

import com.visikard.application.UIMessage;
import com.visikard.business.CouponBusManage;
import com.visikard.item.CreateCouponParams;
import com.visikard.response.CreateCpResponse;

public class CreateCouponAsyncTask extends BaseTask {
	public static final int POS_PATHFILE = 0;
	public static final int POS_USERID = 1;
	public static final int POS_MERCHANTID = 2;

	private CreateCouponParams mCouponParams;

	public CreateCouponAsyncTask(Handler handler, CreateCouponParams params) {
		super(handler);
		this.mCouponParams = params;
	}

	public CreateCouponAsyncTask(Handler handler, boolean isShowProgress, CreateCouponParams params) {
		super(handler, isShowProgress);
		this.mCouponParams = params;
	}

	@Override
	protected Object doBackgroundWork(Object... params) {

		CouponBusManage busObj = new CouponBusManage();

		return busObj.createCoupon(params[POS_PATHFILE].toString(), params[POS_USERID].toString(),
				params[POS_MERCHANTID].toString(), mCouponParams);
	}

	@Override
	protected boolean handleResult(Object result) {
		CreateCpResponse response = (CreateCpResponse) result;
		if (response != null) {
			Message successMsg = new Message();
			successMsg.what = UIMessage.MSG_CREATE_COUPON_FINISH;
			successMsg.obj = result;
			mUIHandler.sendMessage(successMsg);

		}
		return false;
	}
}
